#include "../Base/Log.h"
#include "RenderEngine.h"

#include "SpaceLine.h"

namespace cy_univerX
{
namespace render
{

	CSpaceLinePool::CSpaceLinePool(int size)
	{
		SetNewPoolNodeSize(size);
		NewPoolNode();
		m_CurrUsed = m_Pools.begin();
	}
	CSpaceLinePool::~CSpaceLinePool()
	{
		for (T_SpaceLinePoolList::iterator i = m_Pools.begin(); i != m_Pools.end(); ++i)
		{
			delete (*i);
		}
	}

	CSpaceLinePool& CSpaceLinePool::Instance(int size)
	{
		static CSpaceLinePool g_instance(size);
		return g_instance;
	}

	void CSpaceLinePool::RenderLine(const math::CVector3f &pos1, const math::CVector3f &pos2, const math::CColor4f &color)
	{
		if (!(*m_CurrUsed)->RenderLine(pos1, pos2, color))
		{
			NewPoolNode();
			m_CurrUsed = m_Pools.end();
			--m_CurrUsed;
			(*m_CurrUsed)->RenderLine(pos1, pos2, color);
		}
	}
	void CSpaceLinePool::RenderLine(const math::CVector2f &pos1, const math::CVector2f &pos2, const math::CColor4f &color)
	{
		if (!(*m_CurrUsed)->RenderLine(pos1, pos2, color))
		{
			NewPoolNode();
			m_CurrUsed = m_Pools.end();
			--m_CurrUsed;
			(*m_CurrUsed)->RenderLine(pos1, pos2, color);
		}
	}

	void CSpaceLinePool::Flush()
	{
		for (T_SpaceLinePoolList::iterator i = m_Pools.begin(); i != m_CurrUsed; ++i)
		{
			(*i)->Flush();
		}
		(*m_CurrUsed)->Flush();
		m_CurrUsed = m_Pools.begin();
	}



}
}